TemplateAttributesViewForm = Ext
		.extend(
				Ext.Window,
				{
					formPanel : null,
					constructor : function(a) {
						Ext.applyIf(this, a);
						this.initUIComponents();
						TemplateAttributesViewForm.superclass.constructor.call(
								this, {
									layout : "form",
									items : [this.intrinsicFormPanel,this.formPanel],
									modal : true,
									id : "TemplateAttributesViewFormWin",
									title : "物料模板属性维护",
									iconCls : "menu-role",
									width : 720, 
									buttonAlign : "center",
									buttons : this.buttons
								});
					},
					initUIComponents : function() {
						this.toolbar = new Ext.Toolbar({
							height : 30,
							items : [ new Ext.Button({
								text : "添加属性",
								iconCls : "btn-add",
								handler : function() {
									var cmp = Ext.getCmp("TemplateAttributesViewForm.template.id");
									new TemplateAttributesForm({
										tId : cmp.value
									}).show();
								}
							})]
						});
						this.intrinsicFormPanel=new Ext.FormPanel({
						    layout : "form",
						    border : false,
						    height:280,
						    title:"原有属性",
                            autoScroll: true,  
                            bodyStyle : "padding:5px;",
                            defaults : {
                                anchor : "99%,99%"
                            },
                            defaultType : "textfield",
                            items:[]
						});
						this.formPanel = new Ext.FormPanel(
								{
									tbar : this.toolbar,
									url : __ctxPath +  "/system/saveTemplate.do",
									layout : "form",
									title:"扩展属性",
									id : "TemplateAttributesViewForm",
									border : false,
									height:190,
									autoScroll: true,  
									bodyStyle : "padding:5px;",
									defaults : {
										anchor : "96%,99%"
									},
									formId : "TemplateAttributesViewFormId",
									//defaultType : "textfield",
									items : [
											{
												id : "TemplateAttributesViewForm.template.id",
												name : "template.id",
												xtype : "hidden",
												value : this.id == null ? ""
														: this.id
											},											
											{
												xtype : "fieldset",
												id : "attrsFieldset",
												columnWidth : 0.5,
											
												collapsed : false,
												border : false,
												//collapsible : true,
												autoHeight : true,
												defaults : {
													anchor : "96%,90%"
												},
												items : []
											}
									]
								});
						if (this.id != null && this.id != "undefined") {
							this.formPanel.loadData({
										url : __ctxPath
												+ "/system/getTemplate.do?id="
												+ this.id,
										preName : "template",
										root : "result" ,
										success : function(form, action) {  
											var g = Ext.util.JSON.decode(form.responseText).result; 
											if(g){     
												var tavfWin=Ext.getCmp("TemplateAttributesViewFormWin");  
												tavfWin.initAttributes(g.attributes);  
											}
				                        } 
									});
						}
					}
/*					save : function() {
						var b = Ext.getCmp("TemplateAttributesViewForm");
						if (b.getForm().isValid()) {
							b.getForm().submit(
											{
												method : "post",
												waitMsg : "正在提交数据...",
												success : function(e,f) {
													Ext.ux.Toast
															.msg(
																	"操作提示",
																	"信息保存成功！");
//													Ext
//															.getCmp(
//																	"MaterialTemplateGrid")
//															.getStore()
//															.reload();
													Ext.getCmp("TemplateAttributesViewFormWin").close();
												},
												failure : function(
														e,
														f) {
													Ext.MessageBox
															.show({
																title : "操作提示",
																msg : "信息保存出错，请联系管理员！",
																buttons : Ext.MessageBox.OK,
																icon : "ext-mb-error"
															});
													Ext
															.getCmp(
																	"MaterialTemplateFormWin")
															.close();
												}
											});
						}
					}*/
				}); 
TemplateAttributesViewForm.prototype.delAttr=function(a){
	Ext.Msg.confirm("信息确认", "您确认要删除该属性吗？", function(c) {
		if (c == "yes") {
			Ext.Ajax.request({
				url : __ctxPath + "/system/deleteTemplateAttributes.do",
				params : {
					ids : a.id,
					tId : Ext.getCmp("TemplateAttributesViewForm.template.id").getValue()
				},
				method : "post",
				success : function(a) {
					var result=Ext.util.JSON.decode(a.responseText); 
					if(result.success){
						Ext.ux.Toast.msg("信息", "成功删除属性！");
					  	var templateWin=Ext.getCmp("TemplateAttributesViewFormWin");  
						templateWin.initAttributes(result.result); 
					}else{ 
						Ext.MessageBox.show({
							title : "操作提示",
							msg : result.msg,
							buttons : Ext.MessageBox.OK,
							icon : "ext-mb-error"
						});
					}
				}
			});
		}
	});
};
TemplateAttributesViewForm.prototype.initAttributes = function(attrs) { 
	this.formPanel.findById("attrsFieldset").removeAll();
	if (!attrs) return;
	var len = attrs.length;
	var s = len % 2;
	if (s == 0) {
		for ( var i = 0; i < len; i = i + 2) {
			var attr1=attrs[i];
			var attr2=attrs[i+1];
			var fd = {
				layout : "column",
				items : [ {
					columnWidth : .5,//第一列 
					layout : "column",
					border : false,
					bodyStyle : "padding:5px;",
					items : [ 
					  {
							columnWidth : .5,
							xtype : "label", 
							text:attr1.taFieldName+':',
							width : 140
						 },   
					  { 
						xtype : "textfield",
						fieldLabel : attr1.taFieldName,
						name : attr1.taField,
						value:attr1.taFieldValue,
						readOnly:true,
						width : 130
					},{ 
						iconCls : "btn-delete", 
						xtype:'button',  
						id:attr1.id,
						handler :this.delAttr
					}]
				}, {
					columnWidth : .5,//第二列 
					layout : "column",
					border : false,
					bodyStyle : "padding:5px;",
//					labelWidth : 120,
					items : [  
					  {
							columnWidth : .5,
							xtype : "label", 
							text:attr2.taFieldName+':',
							width : 140
						 },   
					  { 
						xtype : "textfield",
						fieldLabel : attr2.taFieldName,
						name : attr2.taField,
						value:attr2.taFieldValue,
						readOnly:true,
						width : 130
					},{ 
						iconCls : "btn-delete", 
						scope : this,
						xtype:'button',
						id:attr2.id,
						handler : this.delAttr
					}
					]
				} ]
			}; 
			this.formPanel.findById("attrsFieldset").add(fd);
		}
	} else {
		for ( var i = 0; i < len-1; i = i + 2) {
			var attr1=attrs[i];
			var attr2=attrs[i+1];
			var fd = {
				layout : "column",
				items : [ {
					columnWidth : .5,//第一列 
					layout : "column",
					labelWidth : 120,
					border : false,
					bodyStyle : "padding:5px;",
					items : [
					         {
									columnWidth : .5,
									xtype : "label", 
									text:attr1.taFieldName+':',
									width : 140
								 },   
							  { 
								xtype : "textfield",
								fieldLabel : attr1.taFieldName,
								name : attr1.taField,
								value:attr1.taFieldValue,
								readOnly:true,
								width : 130
							},{ 
								iconCls : "btn-delete", 
								scope : this,
								xtype:'button',
								id:attr1.id,
								handler : this.delAttr
							}
					
					]
				}, {
					columnWidth : .5,//第二列 
					layout : "column",
					border : false,
					bodyStyle : "padding:5px;",
					labelWidth : 120,
					items : [  
					         {
									columnWidth : .5,
									xtype : "label", 
									text:attr2.taFieldName+':',
									width : 140
								 },   
							  { 
								xtype : "textfield",
								fieldLabel : attr2.taFieldName,
								name : attr2.taField,
								value:attr2.taFieldValue,
								readOnly:true,
								width : 130
							},{ 
								iconCls : "btn-delete", 
								scope : this,
								xtype:'button',
								id:attr2.id,
								handler : this.delAttr
							}
					           ]
				} ]
			};
			this.formPanel.findById("attrsFieldset").add(fd);
		}
		var attr1=attrs[len-1];
		var fd = {
				layout : "column",
				items : [ {
					columnWidth : .5,//第一列 
					layout : "column",
					labelWidth : 120,
					border : false,
					bodyStyle : "padding:5px;",
					items : [ 
					         {
									columnWidth : .5,
									xtype : "label", 
									text:attr1.taFieldName+':',
									width : 140
								 },   
							  { 
								xtype : "textfield",
								fieldLabel : attr1.taFieldName,
								name : attr1.taField,
								value:attr1.taFieldValue,
								readOnly:true,
								width : 130
							},{ 
								iconCls : "btn-delete", 
								scope : this,
								xtype:'button',
								id:attr1.id,
								handler : this.delAttr
							}      
					          ]
				}
			 ]}
		this.formPanel.findById("attrsFieldset").add(fd);
	}
	this.formPanel.findById("attrsFieldset").doLayout();
	
}